#usage: python search.py packagename [more package names]

import sys
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib

def package_sh(*args, **kwargs):
    print(args[1])
    
def destroy_sh(*args, **kwargs):
    loop.quit()

DBusGMainLoop(set_as_default=True)
system_bus = dbus.SystemBus()

pk_object = system_bus.get_object("org.freedesktop.PackageKit", "/org/freedesktop/PackageKit")
pk_interface = dbus.Interface(pk_object, "org.freedesktop.PackageKit")

pk_transaction = pk_interface.CreateTransaction()

pk_transaction_object = system_bus.get_object("org.freedesktop.PackageKit", pk_transaction)
pk_transaction_interface = dbus.Interface(pk_transaction_object, "org.freedesktop.PackageKit.Transaction")

pk_transaction_interface.connect_to_signal('Package',package_sh)
pk_transaction_interface.connect_to_signal('Destroy', destroy_sh)
GLib.timeout_add(500, pk_transaction_interface.SearchNames, 0,sys.argv[1:])

loop = GLib.MainLoop()
loop.run()